package IOPerations;

import Books.Book;
import Books.BooksList;

import java.util.Scanner;

public class AddOperations implements IOperations {

    //添加书籍
    @Override
    public void work(BooksList booksList) {
        System.out.println("新增书籍");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名");
        String name = scanner.nextLine();
        System.out.println("请输入书作者");
        String author = scanner.nextLine();
        System.out.println("请输入书的类型");
        String type = scanner.nextLine();
        System.out.println("请输入书的价格");
        int price = scanner.nextInt();

        Book book = new Book(name,author,price,type);

        int tmp = booksList.getVal();
        for (int i = 0; i < tmp; i++) {
            if (booksList.getBook(i).getName().equals(name)){
                System.out.println("你好 你输入的这本书已经在书架上面了");
            }else {
                booksList.setBooks(book,tmp);
                booksList.setVal(tmp + 1);
                System.out.println("添加成功!!");
            }
        }
    }
}
